package com.zzw.schedule;

import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author Administrator
 */
@Configuration
@EnableScheduling
@EnableAsync
public class ScheduleConfiguration {

    @Bean
    @ConditionalOnBean(RedissonClient.class)
    public DefaultAsyncRTask defaultAsyncRTask(RedissonClient redissonClient) {
        return new DefaultAsyncRTask(redissonClient);
    }

    @Bean
    @ConditionalOnMissingBean
    public Executor taskExecutor() {
        return Executors.newFixedThreadPool(5);
    }
}
